package org.autumn.jmm;

import java.util.concurrent.TimeUnit;

public class Test {
    static int x;
    public static void main(String[] args) throws InterruptedException {

        Thread t2 = new Thread(() -> {
            while (true){

                if (Thread.currentThread().isInterrupted()){
                    System.out.println(x);
                    break;
                }
            }
        }, "t2");
        t2.start();


        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            x = 10;
            t2.interrupt();
        }, "t1").start();


        while (!t2.isInterrupted()){

        }
        System.out.println("main"+x);
    }
}
